<?php
$tblproduct = new Zendvn_Model_Table_Product();
if(isset($this->arrParam['cat_id'])){
	$products = $tblproduct->listItem($this->arrParam,array("task"=>"related"));
}else if($this->arrParam['action']=="product-category"){
	$products = $tblproduct->listItem($this->arrParam,array("task"=>"related-non"));
}else{
	$products = $tblproduct->listItem($this->arrParam,array("task"=>"related-all"));
}

if(!empty($products) && $this->arrParam['action']!= 'contact'):
	$filter = new Zendvn_Filter_Filter();
?>

<div class="box-header">
                	<h3>Sản phẩm liên quan</h3>
                </div>
                <div class="relative_product">
				   <?php 
				   $config = new Zendvn_Controller_Config(array('module'=>'admin',
												'fileConfig'=>'product-category.ini'));
					$itemConfig = $config->getconfig('item');
					$imgUrlThumb = FILE_URL . '/product/items/';
					$imgUrl 	= FILE_URL . '/product/items/';
					$imgPathThumb = FILE_PATH . '/product/items/';
				   foreach($products as $val){
				   		$id			= $val['id'];
				   		$cat_id		= $val['cat_id'];
				   		$name		= Zendvn_Filter_Filter::filterContent($val['name'], 'filter');
						$price 		= $val['price'];
						$sell_off 	= $val['sale_price'];
						$newPrice 	= (empty($sell_off) || $sell_off == 0)?$price:$sell_off;
						$imgPathThumb . $val['image'];
						if(file_exists($imgPathThumb . $val['image']) && !empty($val['image'])){
							$imgThumb = $imgUrlThumb . $val['image'];
							$imgOrginal = $imgUrlThumb . $val['image'];
						}else{
							$imgThumb = $imgOrginal = FILE_URL . '/no-image.png';
						}
						
						$linkProduct = $this->cmsUrl(array(
								'module' => 'default',
								'controller' => 'index',
								'action' => 'product-detail',
								'cat_id' => $cat_id,
								'id' => $id,
								'title' => $filter->filter($name)
						), 'product-detail');
						
						$linkOrder = $this->cmsUrl(array(
									'module' => 'default',
									'controller' => 'index',
									'action' => 'order',
									'product_id' => $id
									));
							
				   ?>   
				
                    <div class="lev">
                        <div class="product_name">
                            <a href="<?php echo $linkProduct?>"><?php echo $name?></a>
                        </div>
                        <div class="product_img">
                            <a href="<?php echo $linkProduct?>"><img src="<?php echo $imgThumb?>" /></a>
                        </div>	
                        <div class="product_info">
                            <div class="price">
                            	<?php if(!empty($sell_off) || $sell_off != 0):?>  
                                <span class="normal-price"><?php echo number_format($price)?></span>
                                <?php endif;?>
                                <span class="special-price"><?php echo number_format($newPrice)?></span>
                            </div>
                            <div class="button">
                                <a href="<?php echo $linkOrder?>" onclick="return fancyBox(this)">Đặt hàng</a>
                            </div>
                        </div>	
                        <?php if(!empty($sell_off) || $sell_off != 0):?>  
                        <span class="sale_icon"></span>
                        <?php endif;?>
                    </div>
                <?php
					}
				?>   
               	</div>
               	<?php endif;?>